<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWordBankTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('book_word', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('book_id')->default(0)->comment('书籍ID');
            $table->integer('book_chapter_id')->default(0)->comment('章节ID');
            $table->string('en_word')->index()->default('')->comment('英文单词');
            $table->string('cn_word')->index()->default('')->comment('中文单词');
            $table->string('en_audio')->default('')->comment('英文音频');
            $table->string('cn_audio')->default('')->comment('中文音频');
            $table->string('opt_two')->default('')->comment('第2个选项');
            $table->string('opt_thr')->default('')->comment('第3个选项');
            $table->string('opt_four')->default('')->comment('第4个选项');

            $table->timestamps();

            $table->unique(['book_id', 'book_chapter_id','en_word','cn_word'],'book_chapter_word_uniq');

        });

        Schema::create('user_book_chapter', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->default(0)->comment('用户ID');
            $table->integer('book_id')->default(0)->comment('书籍ID');
            $table->integer('book_chapter_id')->default(0)->comment('章节ID');
            $table->integer('cor_word_ct')->default(0)->comment('正确单词数');
            $table->integer('error_cn_audio')->default(0)->comment('错误单词数');

            $table->timestamps();

            $table->unique(['user_id', 'book_id','book_chapter_id'],'user_book_chapter_uniq');
        });

        Schema::create('user_chapter_word', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->default(0)->comment('用户ID');
            $table->integer('book_id')->default(0)->comment('书籍ID');
            $table->integer('book_chapter_id')->default(0)->comment('章节ID');
            $table->integer('book_word_id')->default(0)->comment('书籍单词ID');
            $table->string('select_opt')->default('')->comment('选择的选项');
            $table->integer('is_right')->default(0)->comment('是否正确');

            $table->timestamps();

            $table->index(['user_id', 'book_id','book_chapter_id','book_word_id'],'user_book_chapter_word_uniq');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('word_bank');
        Schema::dropIfExists('user_read_progress');
    }
}
